home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / wpa_supplicant / action_wpa.sh next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2009-10-17  |  1.6 KB  |  82 lines

  1. #!/bin/sh
  2.  
  3. # Action script to enable/disable wpa-roam interfaces in reaction to
  4. # pm-action or ifplugd events.
  5. #
  6. # Copyright: Copyright (c) 2008-2009, Kel Modderman <kel@otaku42.de>
  7. # License:   GPL-2
  8. #
  9.  
  10. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  11.  
  12. if [ ! -x /sbin/wpa_action ]; then
  13.     exit 0
  14. fi
  15.  
  16. SELF=action_wpa
  17. COMMAND=
  18. IFPLUGD_IFACE=
  19.  
  20. # pm-action(8) - <action> <suspend method>
  21. #
  22. # On suspend|hibernate, disconnect any wpa-roam managed interfaces,
  23. # reconnect it on resume|thaw.
  24. #
  25. # The help action must be supported (but can be no-op).
  26.  
  27. case "${1}" in
  28.         suspend|hibernate)
  29.                 COMMAND=disconnect
  30.                 ;;
  31.         resume|thaw)
  32.                 COMMAND=reconnect
  33.                 ;;
  34.     help)
  35.         exit 0
  36.         ;;
  37. esac
  38.  
  39. if [ -z "$COMMAND" ]; then
  40.     # ifplugd(8) - <iface> <action>
  41.     #
  42.     # If an ifplugd managed interface is brought up, disconnect any
  43.     # wpa-roam managed interfaces so that only one "roaming" interface
  44.     # remains active on the system.
  45.  
  46.     IFPLUGD_IFACE="${1}"
  47.  
  48.     case "${2}" in
  49.         up)
  50.             COMMAND=disconnect
  51.             ;;
  52.         down)
  53.             COMMAND=reconnect
  54.             ;;
  55.         *)
  56.             echo "${SELF}: unknown $0 arguments: ${@}" >&2
  57.             exit 1
  58.             ;;
  59.         esac
  60. fi
  61.  
  62. if [ -z "$COMMAND" ]; then
  63.     echo "${SELF}: unknown arguments: ${@}" >&2
  64.     exit 1
  65. fi
  66.  
  67. for CTRL in /var/run/wpa_supplicant/*; do
  68.     [ -S "${CTRL}" ] || continue
  69.  
  70.     IFACE="${CTRL#/var/run/wpa_supplicant/}"
  71.  
  72.     wpa_action "${IFACE}" check || continue
  73.  
  74.     if [ "${IFPLUGD_IFACE}" ] && [ "${IFPLUGD_IFACE}" = "${IFACE}" ]; then
  75.         # if ifplugd is managing this interface (not likely but..)
  76.         # do nothing
  77.         continue
  78.     fi
  79.  
  80.     wpa_cli -i "${IFACE}" "${COMMAND}"
  81. done
  82.